// Include this file ONLY when current.path[2] is defined
- var base = '/docs/' + current.path[1] + '/' + current.path[2] + '/';
- var dir = current.path[4] ? current.path[3] + '/' : '';
- var cur = current.path[4] || current.path[3];
- cur = cur === 'index' ? '' : cur + '.html';
- cur = base + dir + cur;

- var sections = function(dir, selector) {
-    var secondaryPath = public.docs[current.path[1]][current.path[2]]
-    var data = dir ? secondaryPath[dir] && secondaryPath[dir]._data : secondaryPath._data;
-    if (!data) return [];

-    var section = [];
-    var selector = selector || function() { return true; };
-    var prefix = base + (dir ? dir + '/' : '');
-    for (prop in data) {
-      var item = data[prop];
-      item.slug = prop;
-      if (prop[0] !== '_' && !item.hide && selector(item)) {
-        var file = pro
-        var ext = prop.lastIndexOf('/') === prop.length-1 ? '' : '.html';
-        var file = prop === 'index' ? '' : prop + ext;
-        var href = prefix + file;
-        item.class = cur === href ? 'is-selected' : '';
-        item.file = file;
-        item.href = href;
-        item.navTitle = item.navTitle || item.title;
-        item.tooltip = item.description || item.intro || item.title || '';
-        section.push(item);
-      }
-    }
-    return section;
-  }

- var tutorial = sections('tutorial');
- var cookbook = sections('cookbook');
- var basics = sections('guide', function(item) { return item.basics; });
- var guide  = sections('guide', function(item) { return !item.basics; });
- var qs = sections('', function(item) { return item.slug === 'quickstart'; })[0] || {};
- var reference  = sections('', function(item) { return item.reference; });
- var anyItemSelected = function(items) {
-   var selectedCount = items.filter(function(item) { return !!item.class; }).length;
-   return selectedCount > 0 ? 'is-nav-title-selected' : '';
- }
- var isQuickstartSelected = function() {
-   var splitted = cur.split('/');
-   var bit = splitted[splitted.length - 1].replace('.html', '');
-   return bit === 'quickstart' ? 'is-nav-title-selected' : '';
-}
- var isApiReferenceSelected = function() {
-   var splitted = cur.split('/');
-   var bit = splitted[splitted.length - 2];
-   return bit === 'api' ? 'is-nav-title-selected' : '';
-}
- var isCollapsed = function(titleStyle) {
-   return titleStyle === 'is-nav-title-selected' ? '' : 'is-hidden';
- }

nav.side-nav.l-pinned-left.l-layer-4.l-offset-nav
  // SEARCH BAR
  header.side-nav-search.st-input-wrapper
    form.st-input-inner
      label(for="search-io" class="is-hidden") 搜索文档
      input(type="search" id="search-io" placeholder="搜索文档...")
    button(class="mobile-trigger button" aria-label="查看文档菜单" ng-click="appCtrl.toggleDocsMenu($event)" md-button) 文档 <span class="icon icon-arrow-drop-down"></span>

  div(class="side-nav-secondary" ng-class="appCtrl.showDocsNav ? 'is-visible' : ''")
    .nav-blocks
      a(class="nav-title #{isQuickstartSelected(cur)}" href="#{qs.href}" title="#{qs.tooltip}") 快速起步

    .nav-blocks
      a(class="nav-title #{anyItemSelected(tutorial)}" href="#{tutorial[0].href}" title="#{tutorial[0].tooltip}") 教程
        img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")
      .nav-ordered-lists(class="#{isCollapsed(anyItemSelected(tutorial))}")
        ul
          each item, index in tutorial
            li(class="nav-list-item #{item.class}")
              a.translated-cn(href="#{item.href}" title="#{item.tooltip}") #{index + 1}. #{item.navTitle}

    .nav-blocks
      a(class="nav-title #{anyItemSelected(basics)}" href="#{basics[0].href}" title="#{basics[0].tooltip}") 基础知识
        img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")

      .nav-ordered-lists(class="#{isCollapsed(anyItemSelected(basics))}")
        ul
          each item, index in basics
            li(class="nav-list-item #{item.class}")
              a.translated-cn(href="#{item.href}" title="#{item.tooltip}") #{index + 1}. #{item.navTitle}

    .nav-blocks
      a(class="nav-title #{anyItemSelected(guide)}" href="#{guide[0].href}" title="#{guide[0].tooltip}") 开发指南
        img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")

      .nav-unordered-lists(class="#{isCollapsed(anyItemSelected(guide))}")
        ul
          each item in guide
            li(class="nav-list-item #{item.class}")
              a.translated-cn(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}

    .nav-blocks
      a(class="nav-title #{anyItemSelected(cookbook)}" href="#{cookbook[0].href}" title="#{cookbook[0].tooltip}") 烹饪宝典
        img(class="inline-arrow-down-svg" src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg")

      .nav-unordered-lists(class="#{isCollapsed(anyItemSelected(cookbook))}")
        ul
          each item in cookbook
            li(class="nav-list-item #{item.class}")
              a.translated-cn(href="#{item.href}" title="#{item.tooltip}") #{item.navTitle}

    .nav-blocks
      a.translated-cn(class="nav-title #{isApiReferenceSelected()}" href="#{reference[0].href}" title="#{reference[0].tooltip}") API参考手册

script.
  // Could put in appCtrl but only needed here and clear here
  (function scrollToSelectedLink() {
    var sideNav = document.getElementsByClassName('side-nav')[0];
    var link = sideNav.getElementsByClassName('is-selected')[0];
    if (link && link.offsetTop > window.innerHeight) {
      sideNav.scrollTop = link.offsetTop - (window.innerHeight / 2);
      //alert("offsetTop: " + link.offsetTop + " side-nav top is " + sideNav.scrollTop);
    }
  })()
